from django.db import models
from django import newforms as forms

# ============ Constants =============
GRADE_OPTIONS = (
    ("Range", "range from 0 to max_value"),
    ("Letter", "letter from A+ to F-"),
    ("Pass", "pass/nonpass"),
)

# ============ Models ================
class Student(models.Model):
    """
    Holds list of students.
    
    @requires: first_name, second_name
    """
    first_name = models.CharField(maxlength=20)
    middle_name = models.CharField(maxlength=30,blank=True)
    second_name = models.CharField(maxlength=30)
    schoolid = models.CharField(maxlength=30,blank=True,unique=True)
    """@cvar: is a char field that contains unique school/university id, perm number, etc."""
    email = models.EmailField(blank=True)
    phone = models.PhoneNumberField(maxlength=15,blank=True)
    marks= models.ManyToManyField('Mark')
    tanotes = models.ManyToManyField('Tanote')
    """@cvar: is a reference to a note made by a teacher."""
    
    class Admin: pass
    
class Section(models.Model):
    """
    Stores information about partticular group of students: class, section, etc.
    """
    name = models.CharField(maxlength=50)
    schoolid = models.CharField(maxlength=30,blank=True,unique=True)
    """@cvar: is a char field that contains unique school/university
    id number for this class/section"""
    time_day = models.CharField(maxlength=100,blank=True)
    """@cvar: a string that describes what time and when this section is taught,
    the format is not defined"""
    location = models.CharField(maxlength=100,blank=True)
    """@cvar: room number, building, shack, etc., free format"""
    students = models.ManyToManyField('Student')
    tanotes = models.ManyToManyField('Tanote')
    """@cvar: is a reference to a note made by a teacher."""
    
    class Admin: pass
    
class Grade(models.Model):
    """
    Stores information about type of grades, lab, midterm, final grade, etc.
    """
    name = models.CharField(maxlength=20)
    option = models.CharField(maxlength=10, choices=GRADE_OPTIONS, radio_admin=True)
    """@cvar: determines grade option(range from 1 to max_value, letter a to f or pass/nonpass)."""
    max_value = models.IntegerField(blank=True)
    """@cvar: maximum possible value in case of range grading option."""
    tanotes = models.ManyToManyField('Tanote')
    """@cvar: a reference to a note made by a teacher."""
    
    class Admin: pass
    
class Mark(models.Model):
    """
    Stores values of grades/marks given to a student
    
    @requires: must be connected to grade table.
    """
    value = models.CharField(maxlength=10)
    grade = models.ForeignKey(Grade, blank=False)
    """@cvar: required"""
    tanotes = models.ManyToManyField('Tanote')
    """@cvar: a reference to a note made by a teacher."""
    
    class Admin: pass
    
class Tanote(models.Model):
    """
    notes made by teachers about students, grades, etc.
    """
    is_public = models. BooleanField(default=False)
    """@cvar: if True the note will be available for students to read,
    usefull for section descriptions etc."""
    remark = models.TextField()
    """@cvar: text of the note"""
    
    class Admin: pass
    
# ============ Forms =================
class AddSectionForm(forms.Form):
    name = forms.CharField(label='Section name')
    schoolid = forms.CharField(required=False, label='ID number')
    time_day = forms.CharField(required=False, label='Time')
    location = forms.CharField(required=False, label='Locaion')
    public_note = forms.CharField(required=False, widget=forms.Textarea, label='Description')
    private_note = forms.CharField(required=False, widget=forms.Textarea, label='Note for TAs')

